package org.datascooter.generator;

import java.util.HashMap;
import java.util.Map;

import org.datascooter.inface.IIdGenerator;

public class IntIncrementIdGenerator implements IIdGenerator<Integer> {

	private final Integer increment;
	private Integer number = 0;
	private Map<Object, Integer> idMap = new HashMap<Object, Integer>();

	public IntIncrementIdGenerator() {
		this(Long.valueOf(System.currentTimeMillis()).intValue(), 1);
	}

	public IntIncrementIdGenerator(Integer seed, Integer increment) {
		number = seed == null ? 0 : seed;
		this.increment = increment == null ? 1 : increment;
	}

	@Override
	public Integer getId(Object value) {
		Integer result = idMap.get(value);
		if (result == null) {
			number += increment;
			idMap.put(value, number);
			result = number;
		}
		return result;
	}
}
